package com.hnmqet.demo03.controller;


import com.hnmqet.demo03.dao.StorageTblMapper;
import com.hnmqet.demo03.entity.StorageTbl;
import com.hnmqet.demo03.service.StorageTblService;
import com.hnmqet.demo03.service.StorageTccService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author td
 * @since 2020-01-07
 */
@RestController
@RequestMapping
public class StorageTblController {
    @Autowired
    StorageTblService storageTblService;
    @Autowired
    StorageTblMapper storageTblMapper;


    /**
     * 扣减库存
     *
     * @param count
     * @return
     */
    @GetMapping(value = "/decrease")
    void decrease(@RequestParam("code") String code, @RequestParam("count") Integer count) {

        storageTblService.test(code, count);
    }

    @GetMapping("/insert")
    Object insert() {
        StorageTbl storageTbl = new StorageTbl();
        storageTbl.setCount(11);
        storageTbl.setCommodityCode("1122222");
        //storageTbl.setUpdateTime("2020-09-28 10:14:58");
        //storageTbl.setCreateTime("2020-09-28 16:55:51");
        storageTblMapper.insert(storageTbl);

/*
        StorageTbl storageTbl = storageTblMapper.selectById(1L);
        storageTbl.setUpdateTime("2020-09-28 10:14:58");
        storageTbl.setCreateTime("2020-09-28 16:55:51");
        storageTblMapper.updateById(storageTbl);
        System.err.println(storageTbl);
        return storageTbl;*/
        return storageTbl;
    }

    @GetMapping("/update")
    Object update() {
        StorageTbl storageTbl = storageTblMapper.selectById(1L);
        storageTblMapper.updateById(storageTbl);
        return storageTbl;
    }


    @Autowired
    StorageTccService storageTccService;

    /**
     * 扣减库存
     *
     * @param count
     * @return
     */
    @GetMapping(value = "/tcc")
    void tcc(@RequestParam("code") String code, @RequestParam("count") Integer count) {
        storageTccService.reduceStorage(null, code, count);
    }

}

